<?php
/* 
 * Amnesia is Copyright (c) 2010 Mark Russell
 * 
 * Contact: info@amnesia-app.com	
 * 
 * This file is part of Amnesia.
 * 
 * Amnesia is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Amnesia is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Amnesia. If not, see <http://www.gnu.org/licenses/>.
 *
 */

session_start();
include("../db/db.php");
include("../login/login.php");

$username = mysql_real_escape_string ($_POST[username]);
//$password = mysql_real_escape_string ($_POST[password]);

// Send unlogged-in access attempts straight to the login form
if(!$logged_in)
	//header("Location: ../");

// Get the current user from the session

$query = "SELECT `user_id` FROM `user` WHERE `username`='" . $username . "'";

if(!($result = @ mysql_query ($query, $con)))
	showerror();

while($array = mysql_fetch_array($result)) {
	$user_id = $array['user_id'];
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Amnesia. Feel free to forget.</title>
	<link rel="stylesheet" href="../css/amnesia.css" type="text/css" media="screen" />
	<script type="text/javascript" src="../lib/jquery.js"></script>
	<script type="text/javascript" src="../lib/passpack.js"></script>
	<script type="text/javascript" src="../lib/showpassword.js"></script>
	<script type="text/javascript" src="../lib/password.js"></script>
	<script type="text/javascript" src="register.js"></script>
</head>
<body>
	<div id="main">
		<div id="container">
			<div id="left_retainer"></div>
			<div id="col1">
				<img src="../img/core/amnesia_logo.jpg" alt="Amnesia. Feel free to forget" width="187" height="184"/>
				<div id="login_status_locked">
					<strong>Amnesia is locked</strong><br/>Please register
				</div>
			</div>
			
			<!-- Locked single column -->
			<div id="col_container_locked">
				<div id="status_locked">
					<div id="status_left"></div>
					<div id="status_right">
						<div id="amnesia_locked">Amnesia is locked and nobody is signed-in<img class="status_icn" src="../img/core/lock_icon.png" alt="lock_icon" width="9" height="12"/></div>
					</div>
				</div>
				<div id="login">
					<div id="login_contents_register">
						<p id="key_message">Register. Step 2 of 2. Set your master key.</p>
						
						<div id="key_entry_error">
							<strong>Sorry!</strong><br/>
							<span id="error_firstname">
								Your first name is too long. Please make it less than 30 characters.<br/>
							</span>
							<span id="error_firstname_blank">
								You've not told us your first name.<br/>
							</span>
							<span id="error_lastname">
								Your last name is too long. Please make it less than 30 characters.<br/>
							</span>
							<span id="error_lastname_blank">
								You've not told us your last name.<br/>
							</span>
							<span id="error_master_key">
								Your master keys don't match or are blank. Please type them again.<br/>
							</span>
							<span id="error_master_key_length">
								Your master key needs to be at least 12 characters long. Remember, the longer it is the more secure the encryption will be.<br/>
							</span>
						</div>
						
						<p class="text">Thank you <b><? echo $username; ?></b>, half-way there. We need a little more information before you can log-in and get started.</p>
						<div class="rule_top_pad"></div>
						<form action="" method="post">
							<input type="hidden" name="username" id="username" value="<? echo $username; ?>">
							<h4>Tell us your name</h4>
							<p>&nbsp;</p>
							<label class="create_key_label">First name:</label><input id="firstname" name="firstname"/>
							<div class="clear"></div>
							<label class="create_key_label">Last name:</label><input id="lastname" name="lastname"/>
							<div class="clear"></div>
							<div class="rule_top_pad"></div>
							<h4>Set up your master key</h4>
							<p class="text">You must now set up your master key. This is the phrase that will be used to encrypt and decrypt all the information you store here.</p>
							<p class="text">The longer your master key is the more secure your data will be. We suggest either a long memorable sentence or a reasonably long mixture of upper and lower case letters, numbers and other characters. Whatever you choose, your master key needs to be at least 12 characters long. It is also case-sensitive, so be sure to remember it exactly.</p>
							<p class="text">Some examples:</p>
							<ul class="text">
								<li>My first pet was called Desmond</li>
								<li>Bob Dylan plays a mean harmonica</li>
								<li>dr45$Sr5(6T&</li>
								<li>dfJs66hdGDHf645^&dfHD*@e</li>
							</ul>
							<div class="rule_top_pad"></div>
							<h4>Important!</h4>
							<p class="text">Once you've set your master key it can't be changed. If you forget it, there's no way to recover it as nobody else ever has any knowledge of it.</p>
							<p>&nbsp;</p>
							<div id="key_form_inputs">
								<label class="create_key_label">Your new key:</label><input type="password" style="width: 250px;" id="master_key_1" name="master_key_1"/>
								
								<div class="clear"></div>
								<label class="create_key_label">Repeat it here:</label><input type="password" style="width: 250px;" id="master_key_2" name="master_key_2"/>
								
								<div class="clear"></div>
							</div>
							<div id="key_form_checkbox">
							<input id="show_pwd" name="show_pwd" type="checkbox"><label class="show_key" for="show_pwd">Show key as you type</label>
							</div>
							<div class="rule_top_pad"></div>
							<div id="create_key_buttonset">
								<p class="text">I understand that forgetting my key means losing access to my data.</p>
								<a id="create_key" href="javascript:void(0)"><img id="create_key_button" src="../img/buttons/create_key_link.png" alt="create_key_link" width="141" height="22"/></a>
							</div>
						</form>
	
					</div>
				</div>
			</div>
			<div class="clear_top_pad"></div>
		</div>
	</div>
</body>
</html>